package com.cloudpolice.weixin.controller;

import com.cloudpolice.weixin.unit.GetPropertiesClass;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.*;

import static com.netflix.discovery.DiscoveryManager.getInstance;

/**
 * @author 梁昊
 * @date 2019/4/22
 * @function 通用功能控制层
 * @editLog
 */
@RestController
@EnableEurekaClient
@RequestMapping("/universal")     // 通过这里配置使下面的映射都在/users下，可去除
@Api(value = "通用控制层", description = "专用于梁昊所要求的通用方法")
public class UniversalController {
    @Autowired
    GetPropertiesClass getPropertiesClass;

    /**
     * @return 返回当前端口号和版本号
     */
    @ApiOperation(value = "得到当前版本号", notes = "返回：当前版本号")
    @PostMapping("/getPortAndVersion")
    public String getPortAndVersion() {
        return String.format("My port is : %s; My version is : %s"
                , getPropertiesClass.getPort()
                , getPropertiesClass.getVersion());
    }

    /**
     * @return 手动下线
     */
    @ApiOperation(value = "手动下线方法", notes = "返回：当前微服务名和端口号")
    @GetMapping("/downLine")
    public String downLine() {
        getInstance().shutdownComponent();
        return String.format("ApplicationName\"%s\"(Port:%s) is downLine.", getPropertiesClass.getApplicationName(), getPropertiesClass.getPort());
    }

    /**
     * @return 返回当前端口号
     */
    @ApiOperation(value = "得到参数标识", notes = "返回：参数标识")
    @PostMapping("/GetParamSign")
    public String GetParamSign() {
        return String.format("liangHaoSign:\"%s\"", getPropertiesClass.getLiangHaoSign());
    }

}
